<template>
    <div>
      <table-expand
        ref="table"
        :columns="columns"
        :data="data"
        :loading="loading"
        :config="config"
        :pageSizeOpts="pageSizeOpts"
        :pageNavigation="pageNavigation"
        :queryFormItem="queryFormItem"
        :collapseFormItem="collapseFormItem"
        :additionalAction="additionalAction"
        :action="action"
        @loadPage="loadPage"
        @handleCreate="handleCreate"
        @handleDetail="handleDetail"
        @handleEdit="handleEdit"
        @handleDelete="handleDelete"
        @handleDeleteMultiple="handleDeleteMultiple"
        @handleSearch="handleSearch"
        @handleReset="handleReset"
      ></table-expand>
      <edit-modal
        v-bind="editPanel"
        :modelType="modelType"
        :columns="formColumns"
        :rules="rules"
        @submit="handleEditSubmit"
      ></edit-modal>
      <read-modal
        v-bind="readPanel"
        :modelType="modelType"
        :columns="columns"
        :rules="rules"
      ></read-modal>
    </div>
</template>

  <script>
    import editModal from '@/pages/components/editModal.vue';
    import readModal from '@/pages/components/readModal.vue';
    import { typeClassName } from '@/pages/config/classNameMap';
    import mixin from '@/pages/components/mixins/mixin'
    import tableExpand from '@/pages/components/tableExpand.vue';
    import {mapState} from 'vuex'
    import columnsMixin from './config'
    export default {
        components: { editModal, readModal, tableExpand },
        name: 'meterRegisterRecord',
        mixins: [mixin, columnsMixin],
        data () {
            return {
                classObject: null, // 单个实例
                collectionObject: null, // 所有实例
                className: typeClassName['meterRegisterRecord'].className,
                type: typeClassName['meterRegisterRecord'].type,
                modelType: typeClassName['meterRegisterRecord'].modelType,
                isSingleCheck: false,
                editPanel: {
                    width: 1024,
                    zIndex: 100,
                    titleStyle: {},
                    drawer: {
                        show: false
                    },
                    cols: 2,
                    data: {}
                },
                readPanel: {
                    width: 1024,
                    zIndex: 100,
                    titleStyle: {},
                    drawer: {
                        show: false
                    },
                    cols: 2,
                    data: {}
                },
                rules: {
                    maintainStartTime: [
                        { required: true, pattern: /.+/, message: '不能为空', trigger: 'blur' }
                    ],
                    maintainEndTime: [
                        { required: true, pattern: /.+/, message: '不能为空', trigger: 'blur' }
                    ]
                },
                loading: false,
                action: {
                    edit: true,
                    delete: false,
                    detail: true
                },
                config: {
                    search: true,
                    addButton: false,
                    batchDeleteButton: false,
                    tableSizeIcon: true,
                    fullscreenIcon: true,
                    refreshIcon: false,
                    columnSettingIcon: true,
                    action: true,
                    additionalAction: false
                },
                pageSizeOpts: [10, 30, 50, 100],
                pageNavigation: { total: 0, pageSize: 10, pageNumber: 1 },
                view: 'planExecuteRecord' // 页面
            };
        },
        computed: {
            ...mapState('admin/layout', ['currentAccount']),
            additionalAction () {
                return {}
            },
            data () {
                if (!!this.collectionObject) {
                    return this.collectionObject.records.map(d => {
                        return {
                            ...d,
                            ...d.values
                        }
                    })
                } else {
                    return [];
                }
            }
        },
        beforeMount () {
            this.collectionObject = this.$modelObject.create(`${this.modelType}Collection`);
            this.classObject = this.$modelObject.create(this.modelType);
            this.loadPage(this.pageNavigation, null);
        },
        mounted () {},
        methods: {
            /**
             * 编辑弹框打开条件
             * 能源仪表抄表记录, 只能修改、删除本人的记录
             */
            editPanelOpenCondition(data){
                let flag = true;
                if(this.currentAccount.account !== data.createdBy && this.currentAccount.account !== data.updatedBy){
                    flag = false;
                    this.$Message.error('只能修改本人的记录')
                }
                return flag;
            }
        }
    };
  </script>
  <style scoped lang="scss"></style>
